//
//  ServerFactory.swift
//  Exchange
//
//  Created by rui on 2018/4/17.
//  Copyright © 2018年 common. All rights reserved.
//

import Foundation

//public let kAppService = "kAppService"

class ServerFactory {
    
    var serverStatus: ServerStatus = .test
 
    static let  `default` = ServerFactory()
    
    var servers = [String : Serverable]()
    private init() {
        
    }
    func server(identifier: Service) -> Serverable {
        var server: Serverable
        if let ser = servers[identifier.rawValue] {
            server = ser
        }else {
            server = createServer(identifier)
        }
        server.serverStatus = self.serverStatus
        servers.updateValue(server, forKey: identifier.rawValue)
        return server
    }
    
    func createServer(_ identifier: Service) -> Serverable {
        if identifier == Service.app {
            return AppServer()
        }else if identifier == Service.upload {
            return UploadServer()
        }else if identifier == Service.javaTcp {
            return JavaTcpServer()
        }else if identifier == Service.cTcp {
            return CTcpServer()
        }else if identifier == Service.webSocket {
            return WebSocketServer()
        }
        return AppServer()
    } 
    
}
